#!/sbin/openrc-run
# Copyright 1999-2012 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

NAME="apt-cacher-ng"
DAEMON="/usr/sbin/$NAME"
RUNDIR="/var/run/$NAME"
PIDFILE="$RUNDIR/$NAME.pid"
SOCKETFILE="$RUNDIR/$NAME.socket"
DAEMON_OPTS="$DAEMON_OPTS pidfile=$PIDFILE SocketPath=$SOCKETFILE foreground=0"

depend() {
	use net
}

start() {
	ebegin "Starting $NAME"
	checkpath -d -m 0755 -o ${NAME}:${NAME} ${RUNDIR}
	start-stop-daemon --start --exec $DAEMON \
	    --user $NAME --group $NAME \
	    --pidfile $PIDFILE \
	    -- $DAEMON_OPTS
	eend $?
}

stop() {
	ebegin "Stopping $NAME"
	start-stop-daemon --stop --retry 15 --exec $DAEMON \
	    --pidfile $PIDFILE
	rm -f $PIDFILE
	eend $?
}
